package com.ruoyi.wgjlcData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wgjlcData.domain.plat.DataWgjlcCzl;
import com.ruoyi.wgjlcData.domain.vo.TestOneData;
import com.ruoyi.wgjlcData.mapper.DataWgjlcCzlMapper;
import com.ruoyi.wgjlcData.service.IDataWgjlcCzlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 无轨胶轮车-最大操纵力测试项Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-27
 */
@Service
public class DataWgjlcCzlServiceImpl implements IDataWgjlcCzlService
{
    @Autowired
    private DataWgjlcCzlMapper dataWgjlcCzlMapper;

    /**
     * 查询无轨胶轮车-最大操纵力测试项
     * 
     * @param czlId 无轨胶轮车-最大操纵力测试项主键
     * @return 无轨胶轮车-最大操纵力测试项
     */
    @Override
    public DataWgjlcCzl selectDataWgjlcCzlByCzlId(Long czlId)
    {
        return dataWgjlcCzlMapper.selectDataWgjlcCzlByCzlId(czlId);
    }

    /**
     * 查询无轨胶轮车-最大操纵力测试项
     *
     * @param dataTaskId
     * @return 无轨胶轮车-最大操纵力测试项
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataWgjlcCzl>> selectDataWgjlcCzjByDataTaskId(Long dataTaskId) {
        List<DataWgjlcCzl> dataWgjlcCzlEntities = dataWgjlcCzlMapper.selectDataWgjlcCzlByDataTaskId(dataTaskId);
        if (dataWgjlcCzlEntities.size() != 0) {
            dataWgjlcCzlEntities.forEach(item -> {
                if (item.getDataList() != null && item.getDataList().length() != 0) {
                    item.setTestOneDataList(JSON.parseArray(item.getDataList(), TestOneData.class));
                    item.setListSize(item.getTestOneDataList().size());
                }
            });
        }
        return new AsyncResult<>(dataWgjlcCzlEntities);
    }

    /**
     * 修改状态为2
     *
     * @param dataTaskId
     */
    @Override
    public int updateDataWgjlcCzlByDataTaskId(Long dataTaskId) {
        return dataWgjlcCzlMapper.updateDataWgjlcCzlByDataTaskId(dataTaskId);
    }

    /**
     * 查询无轨胶轮车-最大操纵力测试项列表
     * 
     * @param dataWgjlcCzl 无轨胶轮车-最大操纵力测试项
     * @return 无轨胶轮车-最大操纵力测试项
     */
    @Override
    public List<DataWgjlcCzl> selectDataWgjlcCzlList(DataWgjlcCzl dataWgjlcCzl)
    {
        return dataWgjlcCzlMapper.selectDataWgjlcCzlList(dataWgjlcCzl);
    }

    /**
     * 新增无轨胶轮车-最大操纵力测试项
     * 
     * @param dataWgjlcCzl 无轨胶轮车-最大操纵力测试项
     * @return 结果
     */
    @Override
    public int insertDataWgjlcCzl(DataWgjlcCzl dataWgjlcCzl)
    {
        dataWgjlcCzl.setCreateTime(DateUtils.getNowDate());
        return dataWgjlcCzlMapper.insertDataWgjlcCzl(dataWgjlcCzl);
    }

    /**
     * 修改无轨胶轮车-最大操纵力测试项
     * 
     * @param dataWgjlcCzl 无轨胶轮车-最大操纵力测试项
     * @return 结果
     */
    @Override
    public int updateDataWgjlcCzl(DataWgjlcCzl dataWgjlcCzl)
    {
        dataWgjlcCzl.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataWgjlcCzl.getTestOneDataList().isEmpty()) {
            dataWgjlcCzl.setDataList(JSON.toJSONString(dataWgjlcCzl.getTestOneDataList()));
        }
        return dataWgjlcCzlMapper.updateDataWgjlcCzl(dataWgjlcCzl);
    }

    /**
     * 批量新增无轨胶轮车-最大操纵力测试项
     *
     * @param dataWgjlcCzl 无轨胶轮车-最大操纵力测试项
     * @return 结果
     */
    @Override
    public int batchDataWgjlcCzl(List<DataWgjlcCzl> dataWgjlcCzl) {
        return dataWgjlcCzlMapper.batchDataWgjlcCzl(dataWgjlcCzl);
    }

    /**
     * 批量删除无轨胶轮车-最大操纵力测试项
     * 
     * @param czlIds 需要删除的无轨胶轮车-最大操纵力测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcCzlByCzlIds(Long[] czlIds)
    {
        return dataWgjlcCzlMapper.deleteDataWgjlcCzlByCzlIds(czlIds);
    }

    /**
     * 删除无轨胶轮车-最大操纵力测试项信息
     * 
     * @param czlId 无轨胶轮车-最大操纵力测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcCzlByCzlId(Long czlId)
    {
        return dataWgjlcCzlMapper.deleteDataWgjlcCzlByCzlId(czlId);
    }
}
